<?php

namespace common\models\book;

use Yii;
use common\helpers\StringHelper;

/**
 * This is the model class for table "{{%book_waiter}}".
 *
 * @property int $id
 * @property string $name 对接人姓名
 * @property string|null $mobile 对接人手机号
 * @property int $department_id 部门ID
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class BookWaiter extends \common\db\ActiveRecord {

    use \common\traits\Constants;

    /**
     * 状态
     */
    const STATUS_ACTIVE = 10;
    const STATUS_DEFAULT = 0;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%book_waiter}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['name'], 'required'],
            [['department_id', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['name'], 'string', 'max' => 50],
            [['mobile'], 'string', 'max' => 11],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'name' => '对接人姓名',
            'mobile' => '对接人手机号',
            'department_id' => '部门ID',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function getMaskMobile() {
        return $this->mobile ? StringHelper::maskChar($this->mobile) : '-';
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'name',
            'mobile',
            'maskMobile',
            'department_id',
        ];
    }

}
